package DB;

import Communication.MessageHandle;
import Communication.Client;
import Entity.Category;

/** this class asks queries to get and insert category and product details from and into the db  */
public class CategoryProductQuery {

	/**function which get category's details from db */
	public void getCategoryProductDB(Client client, String typeID) 
	{

		/** Prepare queries*/
		String categoryProductQuery = "SELECT * FROM category_product WHERE TypeID = " + "\" , \"" + typeID + "\")";

		/** Get category from category table*/
		client.getData(categoryProductQuery, MessageHandle.CATEGORY_PRODUCT, false);

		try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}

	/**function which insert category and product details into db */
	public void insertCategoryProduct(Client client, Category category, int productid)
	{

		String sql_cat_pro = "INSERT INTO category_product (category_id,product_id) VALUES (\"" + category.getTypeId() +"\" , \"" + productid +"\")";
		client.getData(sql_cat_pro, MessageHandle.CATEGORY_PRODUCT, true);

	}

	/**functions which check if a field is empty */
	public  boolean isEmpty(String field) 
	{
		if (field.isEmpty())
			return true;
		return false;
	}

	public  boolean isEmpty(int field) 
	{
		if (field!=0)
			return true;
		return false;
	}


}
